<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>class SycTimeleap::TimeLeap - RDoc Documentation</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/syctimeleap/time_leap.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link">Object
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-c-new">::new</a>
    
    <li><a href="#method-i-add">#add</a>
    
    <li><a href="#method-i-method_missing">#method_missing</a>
    
    <li><a href="#method-i-next_weekday">#next_weekday</a>
    
    <li><a href="#method-i-next_weekday_in">#next_weekday_in</a>
    
    <li><a href="#method-i-weekday">#weekday</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="../LICENSE.html">LICENSE</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../SycTimeleap.html">SycTimeleap</a>
  
    <li><a href="../SycTimeleap/TimeLeap.html">SycTimeleap::TimeLeap</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class SycTimeleap::TimeLeap</h1>

  <div id="description" class="description">
    
<p>Base class for date operations</p>

  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <!-- Constants -->
    <section id="constants-list" class="section">
      <h3 class="section-header">Constants</h3>
      <dl>
      
        <dt id="WEEKDAYS">WEEKDAYS
        
        <dd class="description"><p>Holds the weekdays of the week starts with sunday at index 0</p>
        
      
      </dl>
    </section>
    

    
    <!-- Attributes -->
    <section id="attribute-method-details" class="method-section section">
      <h3 class="section-header">Attributes</h3>

      
      <div id="attribute-i-now" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">now</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>The base date that is used to calculate date operations</p>
        
        </div>
      </div>
      
    </section><!-- attribute-method-details -->
    

    <!-- Methods -->
    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Class Methods</h3>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(date = Time.now.to_date)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Creates a new Temp and initializes it with the current date if no date is
provided</p>
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/syctimeleap/time_leap.rb, line 23</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">date</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_date</span>)
  <span class="ruby-ivar">@now</span> = <span class="ruby-identifier">date</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- new-source -->
          
        </div>

        

        
      </div><!-- new-method -->

    
    </section><!-- public-class-method-details -->
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-add" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">add</span><span
            class="method-args">(direction, count, distance)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Determines whether to move back or forward in time and returns the distance
in days, weeks, months or years Example: move(10, ‘d’) adds 10 days to :now</p>
          

          
          <div class="method-source-code" id="add-source">
            <pre><span class="ruby-comment"># File lib/syctimeleap/time_leap.rb, line 67</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add</span>(<span class="ruby-identifier">direction</span>, <span class="ruby-identifier">count</span>, <span class="ruby-identifier">distance</span>)
  <span class="ruby-identifier">count</span> = <span class="ruby-identifier">direction</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">==</span> <span class="ruby-string">'b'</span> <span class="ruby-operator">?</span> <span class="ruby-operator">-</span><span class="ruby-identifier">count</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">count</span>.<span class="ruby-identifier">to_i</span>

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">distance</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'d'</span>
    <span class="ruby-ivar">@now</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">count</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'w'</span>
    <span class="ruby-ivar">@now</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">count</span> * <span class="ruby-value">7</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'m'</span>
    <span class="ruby-ivar">@now</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-identifier">count</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'y'</span>
    <span class="ruby-ivar">@now</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-identifier">count</span> * <span class="ruby-value">12</span>
  <span class="ruby-keyword">end</span>

<span class="ruby-keyword">end</span></pre>
          </div><!-- add-source -->
          
        </div>

        

        
      </div><!-- add-method -->

    
      <div id="method-i-method_missing" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">method_missing</span><span
            class="method-args">(name, *args)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Provides the date calculation methods dynamically</p>
          

          
          <div class="method-source-code" id="method_missing-source">
            <pre><span class="ruby-comment"># File lib/syctimeleap/time_leap.rb, line 28</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">name</span>, *<span class="ruby-identifier">args</span>)
  <span class="ruby-identifier">add_regex</span> = <span class="ruby-regexp">%r{
    ^([ib])(?:n|ack)?
    (?:\.|_|-| )?
    (\d+)
    (?:\.|_|-| )?
    ([dwmy])
    (?:ays?|eeks?|onths?|ears?)?$
  }</span>

  <span class="ruby-identifier">weekday_regex</span> = <span class="ruby-regexp">%r{
    ^(tod|tom|y)(?:a?y?|o?r?r?o?w?|e?s?t?e?r?d?a?y?)?$
  }</span><span class="ruby-identifier">i</span>
  
  <span class="ruby-identifier">next_weekday_regex</span> = <span class="ruby-regexp">%r{
    ^(n|p)(?:e?x?t|r?e?v?i?o?u?s?)?
    (?:\.|_| |-)?
    (mo|tu|we|th|fr|sa|su)
    (?:n?|e?s?|d?n?e?s?|u?r?s?|i?|t?u?r?|n?)(?:d?a?y?)$ 
  }</span><span class="ruby-identifier">i</span>

  <span class="ruby-identifier">next_weekday_in_regex</span> = <span class="ruby-regexp">%r{
    ^(mo|tu|we|th|fr|sa|su)
    (?:n?|e?s?|d?n?e?s?|u?r?s?|i?|t?u?r?|n?)(?:d?a?y?)(?:_?)
    (i|b)
    (?:n?|a?c?k?)(?:_?)
    (\d+)(?:_?)([dwmy])(?:a?y?s?|e?e?k?s?|o?n?t?h?s?|e?a?r?s?)$
  }</span><span class="ruby-identifier">i</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">add</span>(<span class="ruby-node">$1</span>, <span class="ruby-node">$2</span>, <span class="ruby-node">$3</span>)      <span class="ruby-keyword">if</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">add_regex</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">weekday</span>(<span class="ruby-node">$1</span>)          <span class="ruby-keyword">if</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">weekday_regex</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">next_weekday</span>(<span class="ruby-node">$1</span>, <span class="ruby-node">$2</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">next_weekday_regex</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">next_weekday_in</span>(<span class="ruby-node">$1</span>, <span class="ruby-node">$2</span>, <span class="ruby-node">$3</span>, <span class="ruby-node">$4</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">next_weekday_in_regex</span>
  <span class="ruby-keyword">super</span> 
<span class="ruby-keyword">end</span></pre>
          </div><!-- method_missing-source -->
          
        </div>

        

        
      </div><!-- method_missing-method -->

    
      <div id="method-i-next_weekday" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">next_weekday</span><span
            class="method-args">(direction, abbreviated_weekday)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Returns the next or previous weekday Exampel: next_monday or n_mo Su Mo Tu
We Th Fr Sa</p>

<pre>0  1  2  3  4  5  6
   x                 Today
         *           Next Wednesday
                     @now + (3 - 1 + 7) % 7 = +2
            x        Today 
*                    Next Sunday
                     @now + (0 - 4 + 7) % 7 = +3
      x              Today
         *           Previous Wednesday
                     @now + (3 - 2 + 7) % -7 = -6
             x       Today
      *              Previous Tuesday
                     @now + (2 - 4 + 7) % -7 = -2</pre>
          

          
          <div class="method-source-code" id="next_weekday-source">
            <pre><span class="ruby-comment"># File lib/syctimeleap/time_leap.rb, line 111</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">next_weekday</span>(<span class="ruby-identifier">direction</span>, <span class="ruby-identifier">abbreviated_weekday</span>)
  <span class="ruby-identifier">count</span> = <span class="ruby-identifier">direction</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">==</span> <span class="ruby-string">'n'</span> <span class="ruby-operator">?</span> <span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-value">-1</span>

  <span class="ruby-identifier">weekday</span> = <span class="ruby-constant">WEEKDAYS</span>[<span class="ruby-identifier">abbreviated_weekday</span>.<span class="ruby-identifier">downcase</span>]
  <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;No valid weekday: #{abbreviated_weekday}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">weekday</span>.<span class="ruby-identifier">nil?</span>

  <span class="ruby-identifier">offset</span> = <span class="ruby-ivar">@now</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{weekday[1]}?&quot;</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">count</span> * <span class="ruby-value">7</span> <span class="ruby-operator">:</span> <span class="ruby-value">0</span>
  <span class="ruby-ivar">@now</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">weekday</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">-</span> <span class="ruby-ivar">@now</span>.<span class="ruby-identifier">wday</span> <span class="ruby-operator">+</span> <span class="ruby-value">7</span>) <span class="ruby-operator">%</span> (<span class="ruby-identifier">count</span> * <span class="ruby-value">7</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">offset</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- next_weekday-source -->
          
        </div>

        

        
      </div><!-- next_weekday-method -->

    
      <div id="method-i-next_weekday_in" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">next_weekday_in</span><span
            class="method-args">(weekday_abbreviation, direction, count, distance)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Returns the next weekday in n days, weeks, month or years Example:
monday_in_3_weeks or mo_i_3_w</p>
          

          
          <div class="method-source-code" id="next_weekday_in-source">
            <pre><span class="ruby-comment"># File lib/syctimeleap/time_leap.rb, line 123</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">next_weekday_in</span>(<span class="ruby-identifier">weekday_abbreviation</span>, <span class="ruby-identifier">direction</span>, <span class="ruby-identifier">count</span>, <span class="ruby-identifier">distance</span>)
  <span class="ruby-identifier">count</span> = <span class="ruby-identifier">direction</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">==</span> <span class="ruby-string">'b'</span> <span class="ruby-operator">?</span> <span class="ruby-operator">-</span><span class="ruby-identifier">count</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">count</span>.<span class="ruby-identifier">to_i</span>
  <span class="ruby-identifier">weekday</span> = <span class="ruby-constant">WEEKDAYS</span>[<span class="ruby-identifier">weekday_abbreviation</span>.<span class="ruby-identifier">downcase</span>]

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">distance</span>.<span class="ruby-identifier">downcase</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;d&quot;</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;w&quot;</span>
    (<span class="ruby-ivar">@now</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">count</span> * <span class="ruby-value">7</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">weekday</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">-</span> <span class="ruby-ivar">@now</span>.<span class="ruby-identifier">wday</span>  
  <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;m&quot;</span>
    <span class="ruby-identifier">future</span> = <span class="ruby-ivar">@now</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-identifier">count</span>
    <span class="ruby-identifier">future</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">weekday</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">future</span>.<span class="ruby-identifier">wday</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;y&quot;</span>
    <span class="ruby-identifier">future</span> = <span class="ruby-ivar">@now</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-identifier">count</span> * <span class="ruby-value">12</span>
    <span class="ruby-identifier">future</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">weekday</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">future</span>.<span class="ruby-identifier">wday</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- next_weekday_in-source -->
          
        </div>

        

        
      </div><!-- next_weekday_in-method -->

    
      <div id="method-i-weekday" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">weekday</span><span
            class="method-args">(weekday)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Returns yesterday, today or tomorrow</p>
          

          
          <div class="method-source-code" id="weekday-source">
            <pre><span class="ruby-comment"># File lib/syctimeleap/time_leap.rb, line 84</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">weekday</span>(<span class="ruby-identifier">weekday</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">weekday</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'tod'</span>
    <span class="ruby-ivar">@now</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'tom'</span>
    <span class="ruby-ivar">@now</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'y'</span>
    <span class="ruby-ivar">@now</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- weekday-source -->
          
        </div>

        

        
      </div><!-- weekday-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.2.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

